<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>首页</title>
    <script th:src="@{/webjars/jquery/3.5.1/jquery.min.js}"></script>
    <script th:inline="javascript">
        $(function () {
            $.get("/players/clubs",function (data) {
                for(club of data){
                    if(club.cid == [[${cid}]]){
                        $("select").append("<option value='"+club.cid+"' selected>"+club.cname+"</option>");
                    }else{
                        $("select").append("<option value='"+club.cid+"'>"+club.cname+"</option>");
                    }
                }
            },"json")
        })

        function del(pid) {
            var pd =confirm("是否要删除？");
            if(pd){
                $.get("/players/del","pid="+pid,function (data) {
                    if(data==1){
                       alert("删除成功！");
                       window.location.reload();
                    }else {
                        alert("删除失败！");
                    }
                })
            }
        }

    </script>
</head>
<body>
    <h2 style="text-align: center">美国职业篮球联盟(NBA)球员信息</h2>
    <div style="margin: 0px auto;width: 950px">
        <form action="/players/list" method="get">
            <tr>
                <td>
                    球员姓名：<input name="pname" type="text" th:value="${pname}"/>
                    所属球队：
                    <select name="cid">
                        <option value="0">请选择</option>
                    </select>
                    <input type="submit" value="查询"/>
                    <a href="/players/add"><input type="button" value="添加新球员信息"></a>
                </td>
            </tr>
        </form>
        <table>
            <tr style="background: pink">
                <td>球员编号</td>
                <td>球员名称</td>
                <td>出生时间(yyyy-MM-dd)</td>
                <td>球员身高(单位：cm)</td>
                <td>球员体重(单位：kg)</td>
                <td>球员位置</td>
                <td>所属球队</td>
                <td>相关操作</td>
            </tr>
            <tr th:each="play,R:${playersList}" th:style="${R.count%2!=0}?'background:antiquewhite':'background:write'">
                <td th:text="${play.pid}"></td>
                <td th:text="${play.pname}"></td>
                <td th:text="${#dates.format(play.birthday,'yyyy-MM-dd')}"></td>
                <td th:text="${play.height}"></td>
                <td th:text="${play.weight}"></td>
                <td th:text="${play.position}"></td>
                <td th:text="${play.cname}"></td>
                <td>
                    <a href="javascript:void(0)" th:onclick="del([[${play.pid}]])">删除</a>
                    <a th:href="@{/players/get/{pid}(pid=${play.pid})}">修改</a>
                </td>

            </tr>
        </table>
        <a th:href="@{/players/list(pageNo=1)}" th:if="${page.pageNum!=1}">首页</a>
        <a th:href="@{/players/list(pageNo=${page.pageNum-1})}" th:if="${page.pageNum>1}">上一页</a>



        <a th:href="@{/players/list(pageNo=${page.pageNum+1})}" th:if="${page.pageNum<page.pages}">下一页</a>
        <a th:href="@{/players/list(pageNo=${page.pages})}" th:if="${page.pageNum!=page.pages}">末页</a>
    </div>
</body>
</html>

